package com.example.hanchen.yongkanggy.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hanchen.yongkanggy.R;

import java.util.ArrayList;
import java.util.List;

public class WarnlitemAdapter extends RecyclerView.Adapter<WarnlitemAdapter.TabViewHolder>{

    private Context mContext;
    private List<String> tabData = new ArrayList<>();
    private OnItemClickListener listener;

    public WarnlitemAdapter(Context context, OnItemClickListener listener) {
        this.mContext = context;
        this.listener = listener;
    }


    public void setTabData(List<String> tabData) {
        this.tabData = tabData;
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public WarnlitemAdapter.TabViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_warnitem, parent, false);
        return new WarnlitemAdapter.TabViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull WarnlitemAdapter.TabViewHolder holder, int position) {
        if(position==0){
            holder.ll_home.setBackgroundResource(R.drawable.bg_pink_four_360);
            holder.tvName.setText("未解除");
            holder.tvName.setBackgroundResource(R.mipmap.icon_red_o);
        }else {
            holder.ll_home.setBackgroundResource(R.drawable.bg_pink_five_360);
            holder.tvName.setText("已解除");
            holder.tvName.setBackgroundResource(R.mipmap.icon_green_o);
        }
    }

    @Override
    public int getItemCount() {
        return tabData.size() == 0 ? 0 : tabData.size();
    }

    class TabViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        LinearLayout ll_home;
        TextView tvName;

        public TabViewHolder(@NonNull View itemView) {
            super(itemView);
            ll_home = itemView.findViewById(R.id.ll_home);
            tvName = itemView.findViewById(R.id.tvName);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            int position = getAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                listener.onItemClick(position);
            }
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int position);

    }
}
